package ius.mantianx.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author starrysky
 * @title: ThyLocalResolver
 * @projectName rev_thymeleaf_boot
 * @description: TODO
 * @date 2021/2/809:28
 */
public class ThyLocalResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
//        @{/index.html(lr='zh_CN')}解析
        String language = httpServletRequest.getParameter("lr");
//        默认
        Locale locale = Locale.getDefault();
        if (StringUtils.hasLength(language)){
            String[] values = language.split("_");
            locale= new Locale(values[0], values[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
